package com.zcl.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zcl.base.feign.ItemFeign;
import com.zcl.base.mapper.ImageMapper;
import com.zcl.base.service.ImageService;
import com.zcl.base.vo.BannerVo;
import com.zcl.comm.pojo.TpImage;
import com.zcl.comm.pojo.TpItem;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service("imageService")
public class ImageServiceImpl implements ImageService {

    @Resource
    private ImageMapper imageMapper;

    @Resource//远程调用
    private ItemFeign itemFeign;
    @Override
    public List<BannerVo> queryBanner() {
        LambdaQueryWrapper<TpImage> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(TpImage::getType,1);
        List<TpImage> list=imageMapper.selectList(wrapper);
        List<BannerVo> list2=list.parallelStream().map(tpImage -> {
            BannerVo vo = new BannerVo();
            BeanUtils.copyProperties(tpImage,vo);
            TpItem tpItem=itemFeign.findById(tpImage.getTargetId());
            BeanUtils.copyProperties(tpItem,vo);
            return vo;
        }).collect(Collectors.toList());
        return list2;
    }
}
